﻿using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using TweetSharp.Model;
using Newtonsoft.Json;
using TweetSharp.Twitter.Model.Converters;

#if !Smartphone
#endif

namespace TweetSharp.Twitter.Model
{
#if !SILVERLIGHT
    [Serializable]
#endif
#if !Smartphone
    [DataContract]
    [DebuggerDisplay("{表情}")]
#endif
    [JsonObject(MemberSerialization.OptIn)]
    public class TwitterEmotion : PropertyChangedBase,
                               IComparable<TwitterEmotion>,
                               IEquatable<TwitterEmotion>,
                               ITwitterModel
    {
        private string _phrase;
        private string _type;
        private string _url;
        private bool _isHot;
        private int _orderNumber;
        private string _category;
        private bool _isCommon;

#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("phrase")]
        public virtual string Phrase
        {
            get { return _phrase; }
            set
            {
                if (_phrase == value)
                {
                    return;
                }
                _phrase = value;
                OnPropertyChanged("Phrase");
            }
        }
#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("type")]
        public virtual string Type
        {
            get { return _type; }
            set
            {
                if (_type == value)
                {
                    return;
                }
                _type = value;
                OnPropertyChanged("Type");
            }
        }
#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("url")]
        public virtual string Url
        {
            get { return _url; }
            set
            {
                if (_url == value)
                {
                    return;
                }

                _url = value;
                OnPropertyChanged("Url");
            }
        }
#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("is_hot")]
        public virtual bool IsHot
        {
            get { return _isHot; }
            set
            {
                if (_isHot == value)
                {
                    return;
                }

                _isHot = value;
                OnPropertyChanged("IsHot");
            }
        }
#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("order_number")]
        public virtual int OrderNumber
        {
            get { return _orderNumber; }
            set
            {
                if (_orderNumber == value)
                {
                    return;
                }

                _orderNumber = value;
                OnPropertyChanged("OrderNumber");
            }
        }
#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("category")]
        public virtual string Category
        {
            get { return _category; }
            set
            {
                if (_category==value)
                {
                    return;
                }

                _category = value;
                OnPropertyChanged("Category");
            }
        }
#if !Smartphone
        [DataMember]
#endif
        [JsonProperty("is_common")]
        public virtual bool IsCommon
        {
            get { return _isCommon; }
            set
            {
                if (_isCommon == value)
                {
                    return;
                }

                _isCommon = value;
                OnPropertyChanged("IsCommon");
            }
        }

#if !Smartphone
        /// <summary>
        /// The source content used to deserialize the model entity instance.
        /// Can be XML or JSON, depending on the endpoint used.
        /// </summary>
        [DataMember]
#endif
        public virtual string RawSource { get; set; }

        #region IComparable<TwitterEmotion> Members

        /// <summary>
        /// Compares the current object with another object of the same type.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>
        /// A value that indicates the relative order of the objects being compared. 
        /// The return value has the following meanings: 
        /// Less than zero: This object is less than the <paramref name="user"/> parameter.
        /// Zero: This object is equal to <paramref name="user"/>. 
        /// Greater than zero: This object is greater than <paramref name="user"/>.
        /// </returns>
        public int CompareTo(TwitterEmotion emo)
        {
            return Phrase.CompareTo(emo.Phrase);
        }

        #endregion

        #region IEquatable<TwitterEmotion> Members

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="emo">The user.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="emo"/> parameter; otherwise, false.
        /// </returns>
        public bool Equals(TwitterEmotion emo)
        {
            if (ReferenceEquals(null, emo))
            {
                return false;
            }
            if (ReferenceEquals(this, emo))
            {
                return true;
            }
            return emo.Phrase == Phrase;
        }

        #endregion

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="emo">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        public override bool Equals(object emo)
        {
            if (ReferenceEquals(null, emo))
            {
                return false;
            }
            if (ReferenceEquals(this, emo))
            {
                return true;
            }
            return emo.GetType() == typeof(TwitterEmotion) && Equals((TwitterEmotion)emo);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            return Phrase.GetHashCode();
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(TwitterEmotion left, TwitterEmotion right)
        {
            return Equals(left, right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(TwitterEmotion left, TwitterEmotion right)
        {
            return !Equals(left, right);
        }
    }
}
